from django.db import models
from users.models import User
# Create your models here.

#车品牌
class Carmodels(models.Model):
    mname = models.CharField(max_length=20,verbose_name='品牌') #车牌名
    logo = models.ImageField(upload_to='static/logo/',verbose_name='车标') #车标

    def __str__(self):
        return self.mname
    class Meta:
        verbose_name_plural='汽车品牌'

#车型
class Cartype(models.Model):
    type_name = models.CharField(max_length=20,verbose_name='车型')

    def __str__(self):
        return self.type_name
    class Meta:
        verbose_name = "车型"  # 单数形式
        verbose_name_plural = "汽车车型"

#车
class Cars(models.Model):
    cname = models.CharField(max_length=20,verbose_name='车名')
    price = models.CharField(max_length=20,verbose_name='报价')
    curl = models.ImageField(upload_to='static/models/',verbose_name='展示图')
    durl = models.ImageField(upload_to='static/details/',verbose_name='实物图')
    type = models.ForeignKey(Cartype,on_delete=models.CASCADE)
    model = models.ForeignKey(Carmodels,on_delete=models.CASCADE)

    def __str__(self):
        return self.cname

    class Meta:
        verbose_name_plural ="汽车总览"


#车辆详情
class Cardetails(models.Model):
    payment = models.IntegerField(verbose_name='首付价')    #首付
    firm = models.CharField(max_length=20,verbose_name='厂商')
    rank = models.CharField(max_length=20,verbose_name='级别')
    endurance = models.CharField(max_length=20,verbose_name='续航')
    charge = models.CharField(max_length=20,verbose_name='快充')
    car = models.ForeignKey(Cars,on_delete=models.CASCADE)

    def __str__(self):
        return self.car.cname

    class Meta:
        verbose_name_plural ="汽车详情"


#库存
class Carinventory(models.Model):
    count = models.IntegerField(verbose_name='数量')
    cars = models.ForeignKey(Cars,on_delete=models.CASCADE)
    class Meta:
        verbose_name_plural ="库存"




#官方图片
class Officeimg(models.Model):
    img = models.ImageField(upload_to='static/details/',verbose_name='实拍图')
    car = models.ForeignKey(Cars,on_delete=models.CASCADE)
    class Meta:
        verbose_name_plural ="汽车详情图"



#评价
class CarEvaluate(models.Model):
    head = models.ImageField(upload_to="static/userhead/", verbose_name='头像')
    ename = models.CharField(max_length=20,verbose_name='用户名')
    evaluate = models.TextField(verbose_name='内容')
    updated_at = models.DateTimeField(auto_now=True,verbose_name='时间')
    Cars = models.ForeignKey(Cars,on_delete=models.CASCADE)
    user = models.ForeignKey(User,on_delete=models.CASCADE)
    def __str__(self):
        return self.ename

    class Meta:
        verbose_name_plural ="用户评论"